package com.suneee.quartz.init;

import java.util.Map;
import com.suneee.quartz.entity.TmallOrderEn;
import com.taobao.api.DefaultTaobaoClient;
import com.taobao.api.TaobaoClient;
import com.taobao.api.request.TradeFullinfoGetRequest;
import com.taobao.api.request.TradesSoldIncrementGetRequest;
import com.taobao.api.response.TradeFullinfoGetResponse;
import com.taobao.api.response.TradesSoldIncrementGetResponse;

public class TmallInterface {

	/**
	 * 查询卖家已卖出的增量交易数据
	 * @param shopMap
	 * @param tmallOrderEn
	 * @return
	 * @throws Exception
	 */
	public static TradesSoldIncrementGetResponse getIncrementOrder(TmallOrderEn tmallOrderEn) throws Exception{
		Map<String,String> shopMap = tmallOrderEn.getShopMap();
		TaobaoClient client = new DefaultTaobaoClient(shopMap.get("proxUrl"), shopMap.get("appKey"), shopMap.get("secret"));
		TradesSoldIncrementGetRequest req = new TradesSoldIncrementGetRequest();
		req.setFields("tid,seller_nick,buyer_nick,title,type,pic_path,trade_from,shipping_type,receiver_name,receiver_country,receiver_state,receiver_city,receiver_district,receiver_town,receiver_address,receiver_zip,receiver_mobile,receiver_phone,total_fee,post_fee,received_payment,payment,has_post_fee,discount_fee,adjust_fee,invoice_name,invoice_type,invoice_kind,created,pay_time,modified,end_time,buyer_message,buyer_memo,buyer_flag,seller_memo,seller_flag,timeout_action_time,status,orders.order_id,orders.oid,orders.tid,orders.pic_path,orders.item_meal_name,orders.refund_status ,orders.outer_iid,orders.snapshot_url,orders.snapshot,orders.timeout_action_time,orders.buyer_rate,orders.seller_rate ,orders.cid,orders.status,orders.title ,orders.type,orders.price ,orders.num_iid ,orders.item_meal_id,orders.sku_id,orders.num,orders.outer_sku_id,orders.order_from,orders.total_fee,orders.payment ,orders.discount_fee,orders.adjust_fee,orders.modified,orders.sku_properties_name,orders.refund_id,orders.is_oversold ,orders.end_time,orders.consign_time,orders.part_mjz_discount,orders.divide_order_fee");
		req.setStartModified(tmallOrderEn.getStartModified()); //开始时间
		req.setEndModified(tmallOrderEn.getEndModified());
		//req.setStatus("WAIT_SELLER_SEND_GOODS");
		req.setType("fixed");
		req.setPageNo(Long.valueOf(tmallOrderEn.getPageNo()));
		req.setPageSize(Long.valueOf(tmallOrderEn.getPageSize()));
		req.setRateStatus("RATE_UNBUYER");
		TradesSoldIncrementGetResponse rsp = client.execute(req, shopMap.get("appSession"));
		return rsp;
	}
	
	
	/**
	 * 获取单笔交易的详细信息
	 * @param tmallOrderEn
	 * @return
	 * @throws Exception
	 */
	public static TradeFullinfoGetResponse getfullinfoOrder(TmallOrderEn tmallOrderEn,Long tid) throws Exception{
		Map<String,String> shopMap = tmallOrderEn.getShopMap();
		TaobaoClient client = new DefaultTaobaoClient(shopMap.get("proxUrl"), shopMap.get("appKey"), shopMap.get("secret"));
		TradeFullinfoGetRequest req = new TradeFullinfoGetRequest();
		req.setFields("tid,seller_nick,buyer_nick,title,type,pic_path,trade_from,shipping_type,receiver_name,receiver_country,receiver_state,receiver_city,receiver_district,receiver_town,receiver_address,receiver_zip,receiver_mobile,receiver_phone,total_fee,post_fee,received_payment,payment,has_post_fee,discount_fee,adjust_fee,invoice_name,invoice_type,invoice_kind,created,pay_time,modified,end_time,buyer_message,buyer_memo,buyer_flag,seller_memo,seller_flag,timeout_action_time,status,orders.order_id,orders.oid,orders.tid,orders.pic_path,orders.item_meal_name,orders.refund_status ,orders.outer_iid,orders.snapshot_url,orders.snapshot,orders.timeout_action_time,orders.buyer_rate,orders.seller_rate ,orders.cid,orders.status,orders.title ,orders.type,orders.price ,orders.num_iid ,orders.item_meal_id,orders.sku_id,orders.num,orders.outer_sku_id,orders.order_from,orders.total_fee,orders.payment ,orders.discount_fee,orders.adjust_fee,orders.modified,orders.sku_properties_name,orders.refund_id,orders.is_oversold ,orders.end_time,orders.consign_time,orders.part_mjz_discount,orders.divide_order_fee,orders.is_sh_ship");
		req.setTid(tid);
		TradeFullinfoGetResponse rsp = client.execute(req, shopMap.get("appSession"));
		return rsp;
	}
}
